package pages;

import org.openqa.selenium.WebElement;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import utiles.BaseAction;

public class RegisterPage {
	AndroidDriver driver;
	BaseAction action;
	public RegisterPage(AndroidDriver driver) {
		this.driver=driver;
		action=new BaseAction(driver);
	}
	
	public WebElement edit_username() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/et_account"));
	}
	
	public WebElement edit_password() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/et_password"));
	}
	
	public WebElement confirm_password() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/et_confirm"));
	}
	
	public WebElement btn_register() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/btn_register"));
	}
	
	public WebElement btn_goBack() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/tv_return"));
	}
	
	public void register(String username,String password,String confirm_password) throws InterruptedException {
		action.type(this.edit_username(),username);
		action.type(this.edit_password(),password);
		action.type(this.confirm_password(), confirm_password);
		action.click(this.btn_register());
	}
	
	public String registerSuccess(String username,String password,String confirm_password) throws InterruptedException {
		register(username,password,confirm_password);
		return action.getToastMsg();
	}
	
	
	public String registerFail(String username,String password,String confirm_password) throws InterruptedException {
		register(username,password,confirm_password);
		return action.getToastMsg();
	}
	
	public LoginPage goBack() throws InterruptedException {
		action.click(this.btn_goBack());
		return new LoginPage(driver);
	}

}
